using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using Dune.Business.Domain.Users;
using Edge.Business.Domain.Application;
using Edge.Business.Domain.Filters;
using Edge.Business.Security;
using Edge.Common.ControlFlow;
using Edge.Common.Mail;
using Edge.Common.Mail.Impl;
using Edge.Common.Services;
using Edge.Common.TextTemplates.Impl.ASPNET;
using Edge.Common.Web;
using Edge.Common.Web.Application;
using Edge.Common.Web.Naming;
using Edge.Common.Web.Navigation;
using Edge.Common.Web.Notification;
using Dune.DAL;
using Dune.Web.AppCode;
using Dune.Web.AppCode;
using Edge.DAL.Common.SessionManagment;
using Edge.DAL.Managers;
using Edge.WebCode;
using log4net;
using log4net.Config;
using log4net.Util;
using NHibernate;
using Dune.Business.Domain.Application;
using Edge.Common.ComponentModel;
using Edge.Common.ComponentModel.Exceptions;
using Edge.Common.ComponentModel.Notification;

namespace Dune.Web
{
    public class Global : BaseGlobal
    {
        

        void Application_Start(object sender, EventArgs e)
        {
            try
            {
                //DOMConfigurator.Configure();

                // setup DAL
                DuneInitializer.Setup(true);

                // TODO use IoC container Spring.NET or CastleProject IoC

               // InitilizeLog4net();

                string appBase = SystemInfo.ApplicationBaseDirectory;

                Locator.AddService<ISessionProvider>(new WebSessionProvider());

                Locator.AddService<INavigationService>(new SimpleNavigationService());


                #region Mail configuration

                SendMailService mailService = new SendMailService();
                SendMailServiceConfigurator mailConfigurator = new SendMailServiceConfigurator(mailService);
                mailConfigurator.Configure();
                Locator.AddService<ISendMailService>(mailService);

                #endregion

                #region Setup text templates

                TextEngineFactory.Instance().Referensec.AddRange(
                    new Assembly[]
                        {
                            typeof(Assert).Assembly, 
                            typeof(Iesi.Collections.ISet).Assembly, 
                            typeof(INavigationService).Assembly,
                            typeof(ILog).Assembly
            });


                #endregion

                #region Filters

                SimpleFiltersManager simpleFiltersManager = new SimpleFiltersManager();
                Locator.AddService<IFiltersManager>(simpleFiltersManager);

                #endregion

                Locator.AddService<INotificationManager>(new NotificationManager());

                Locator.AddService<IEntityDescriptionsService>(new EntityDescriptionsService());

                //Locator.AddService<ISearchesRepository>(new SearchesRepository());

                //Locator.AddService<ISecurityService>(new SecurityService());

                Locator.AddService<IContextObjects>(new ContextObjects());

//                Locator.AddService<IPersonManager<User>>(new PersonManager<User,UserHolder,IUserManager>());
//                Locator.AddService<IPersonManager<Person>>(new PersonManager<Person, PersonHolder, IUserPersonManager>());

            }
            catch (Exception ex)
            {
//                Log.Fatal(ex);
//                RegisterError(ex);
            }

            //Log.Info("Application Started");
        }

       
       
    }
}